package patrol.mobile.com.mobilepatrol.activity.security.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.dl7.recycler.helper.RecyclerViewHelper;

import java.util.ArrayList;
import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.bean.AvoidExplode2Bean;

/**
 * Created by admin on 2018/9/9.
 */

public class EmergencyAvoidExplode2Adapter extends BaseQuickAdapter<AvoidExplode2Bean> {

    private int currentItem = -1;
    private EmergencyAvoidExplodeInner2Adapter emergencyAvoidExplodeInnerAdapter2;
    private List<String> innerList = new ArrayList<>();

    public EmergencyAvoidExplode2Adapter(Context context) {
        super(context);

    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_avoid_explode2;
    }

    @Override
    protected void convert(final BaseViewHolder holder, AvoidExplode2Bean item) {
        RecyclerView innerRecyclerView = holder.getView(R.id.recyclerView);
        emergencyAvoidExplodeInnerAdapter2 = new EmergencyAvoidExplodeInner2Adapter(mContext);
        RecyclerViewHelper.initRecyclerViewV(mContext, innerRecyclerView,
                false, emergencyAvoidExplodeInnerAdapter2);
        innerRecyclerView.setAdapter(emergencyAvoidExplodeInnerAdapter2);
        emergencyAvoidExplodeInnerAdapter2.updateItems(item.getEqList());
        holder.setTag(R.id.iv_arror, holder.getAdapterPosition());
        holder.setTag(R.id.re_spand, holder.getAdapterPosition());


        if (currentItem == holder.getAdapterPosition()) {
            holder.setVisible(R.id.recyclerView, true);
        } else {
            holder.setVisible(R.id.recyclerView, false);
        }

        holder.setOnClickListener(R.id.iv_arror, new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int tag = (int) view.getTag();
                if (tag == currentItem) { //再次点击
                    currentItem = -1; //给 currentItem 一个无效值
                } else {
                    currentItem = tag;
                }
                //通知adapter数据改变需要重新加载
                notifyDataSetChanged(); //必须有的一步
            }
        });
        holder.setOnClickListener(R.id.re_spand, new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int tag = (int) view.getTag();
                if (tag == currentItem) { //再次点击
                    currentItem = -1; //给 currentItem 一个无效值
                } else {
                    currentItem = tag;
                }
                //通知adapter数据改变需要重新加载
                notifyDataSetChanged(); //必须有的一步
            }
        });


        holder.setText(R.id.tv_eqName, item.getEqName());


    }
}
